package com.l024.meet.base;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;

import com.l024.framework.Framework;
import com.l024.framework.utils.Logutils;

/**
 * @author wu_ming_zhi_bei
 * @date 2020/2/27 10:17
 * @Notes
 */
public class BaseAPP extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        /**
         * Application优化
         * 1.必要的组件在程序主页去初始化
         * 2.如果组件一定要在App中初始化，那么尽可能延时
         * 3.非必要的组件，子线程去初始化
         */
        //只在主进程初始化,因为融云服务会有三个进程
        if(getApplicationInfo().packageName.equals(getCurProcessName(getApplicationContext()))){
            Logutils.i("开始初始化:");
            Framework.getFramework().initFramework(this);
        }
    }

    /**
     * 获取当前进程
     */
    public static String getCurProcessName(Context context){
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
        for(ActivityManager.RunningAppProcessInfo appProcessInfo:activityManager.getRunningAppProcesses()){
            if(appProcessInfo.pid == pid){
                return appProcessInfo.processName;
            }
        }
        return null;
    }
}
